<?php

/**
 * controler para stock
 *
 * @author jreyes
 */

require 'class/im/mov/DP/ImStockMovimDP.class.php';
require 'class/im/mov/FN/ImStockMovimFN.class.php';

class StockMovimientoController extends ControllerBase
{
	public function listarStockMovimiento(){		
            $o_ImStockMovimFN= new ImStockMovimFN();       		
            $page = isset($this->requestVars['page']) ? $this->requestVars['page'] : 1;
            $rp = isset($this->requestVars['rp']) ? $this->requestVars['rp'] : 10;
            $sortname = isset($this->requestVars['sortname']) ? $this->requestVars['sortname'] : 'name';
            $sortorder = isset($this->requestVars['sortorder']) ? $this->requestVars['sortorder'] : 'desc';		
            $o_ImStockMovimFN->page = $page;
            $o_ImStockMovimFN->tamPag = $rp;
            $o_ImStockMovimFN->sortCampos = $sortname;
            $o_ImStockMovimFN->sortType   = $sortorder;

            if ($this->requestVars){
                if (array_key_exists('almacenId', $this->requestVars)) {
                    $o_ImStockMovimFN->setAlmId($this->requestVars["almacenId"]) ;   
                }
                if (array_key_exists('articuloId', $this->requestVars)) {
                    $o_ImStockMovimFN->setArtId($this->requestVars["articuloId"]);  
                }                          
            }
            $result = $o_ImStockMovimFN->select();     
            $vars['result'] = $result;
            $vars['StockMovimFN'] = $o_ImStockMovimFN;
            if (array_key_exists('modoBusqueda', $this->requestVars)) {
                $vars['modoBusqueda'] = $this->requestVars["modoBusqueda"];
            }else{
                $vars['modoBusqueda'] = "";
            }
            $this->view->show("im/mov/stockMovimLista",$vars);		
    }
	
    public function listarStockMovimientoForm(){
        if (!isset($vars)){
            $vars = '';
        }        
        $this->view->show("im/mov/stockMovimListaForm",$this->requestVars);
    }      
    
    public function generarMovimientoGrupo($a_listArtStockMovim){
        if (is_array($a_listArtStockMovim)){
            foreach ($a_listArtStockMovim as $iKey => $value){
                $o_ImStockMovimDP= new ImStockMovimDP();        
                $o_ImStockMovimDP->setAlmId($value["almId"]);
                $o_ImStockMovimDP->setArtId($value["artId"]);
                $o_ImStockMovimDP->setIngSal($value["ingSal"]);
                $o_ImStockMovimDP->setCant($value["cant"]);
                $o_ImStockMovimDP->setCantAnt($value["cantAnt"]);
                $o_ImStockMovimDP->setCosto($value["costo"]);
                $o_ImStockMovimDP->setCreaFecha(date("Y-m-d H:i:s"));
                $o_ImStockMovimDP->setCreaUsr($v1);
                $o_ImStockMovimDP->setDocId($value["docId"]);
                $o_ImStockMovimDP->setDocNum($value["docNum"]);
                $o_ImStockMovimDP->setDocReferenNro($value["docReferenNro"]);
                $o_ImStockMovimDP->setDocReferenTipo($value["docReferenTipo"]);       
                $o_ImStockMovimDP->save();
            }            
        }
    }
    
 }
?>